<?php
/*
 * ebiz front
 *
 * HomeController
 *
 * @author allen
 *
 */
//require_once 'BaseController.php';
require_once '../app/core/controllers/BaseController.php';
require_once '../app/controllers/ImageController.php';
require_once '../app/constants/ConfigConstants.php';
require_once '../app/views/HomeView.php';

class HomeController extends BaseController {

    public function index(){
    	//CommonUtil::startTimeFunction();
//    	header("Location: http://".ConfigConstants::$domainPath."/u/cart");
//    	$homePage = new HomeView();
//    	echo $homePage->getHomeView();
//        exit();
        $imageController = new ImageController();
        $captchaImg = $imageController->indexAction(1);

        /**
         * $arr_products[0]表示第一排商品
         * $arr_products[0][1]表示第一排的第一个商品
         * $arr_products[0][1]['desciption']促销信息
         * $arr_products[0][1]['url_title']商品超链接使用的名称
         * $arr_products[0][1]['title']商品名称
         * $arr_products[0][1]['sale_price']贩卖价格
         */


        require_once '../app/services/AAService.php';
        require_once '../app/services/CustomerService.php';
        require_once '../app/services/SpecialProductItemService.php';
        $int_userid = AAService::getCustomer();
        if (!empty($int_userid)) {
            $customerService = new CustomerService();
            $arr_user = $customerService->getCustomerById($int_userid);
            $arr_user = $arr_user[0];
        }
        $specialProductItemService = new  SpecialProductItemService();
        $arr_products = array();
        $arr_types = array(43,44,45,46);//设置要取得的商品促销类型
        foreach ($arr_types as $int_key => $int_type){
            $arr_sproducts = $specialProductItemService->getProductItemsByType($int_type);
            foreach ( $arr_sproducts as $int_skey => $arr_product ){
                $arr_sproducts[$int_skey]['url_title'] = urlencode($arr_product['url_title']);
                $arr_sproducts[$int_skey]['description'] = $arr_product['title'];
                if ($int_type == 43)
                {
                    $arr_sproducts[$int_skey]['imagesrc'] = empty($arr_product['iname'])? ConfigConstants::getDefaultProductImagePath(160) : ConfigConstants::getProductImagePath($arr_product['ifolder'],$arr_product['iname'], 120);
                }
                else
                {
                    $arr_sproducts[$int_skey]['imagesrc'] = empty($arr_product['iname'])? ConfigConstants::getDefaultProductImagePath(160) : ConfigConstants::getProductImagePath($arr_product['ifolder'],$arr_product['iname'], 160);
                }
            }
            $arr_products[$int_key] = $arr_sproducts;
        }

        require_once '../app/views/HomeView.php';
        $homeView = new HomeView();
        $homeView->products = $arr_products;
        $homeView->captchaImg = $captchaImg;
        if ( !empty($arr_user) )
            $homeView->user = $arr_user;
        echo $homeView->getPage();
    }


}



